//
//  HotCarPictureViewController.m
//  CarWorld
//
//  Created by yuyu on 15/3/31.
//  Copyright (c) 2015年 CarWorldTeam. All rights reserved.
//

#import "HotCarPictureViewController.h"
#import "HotPictureDetailView.h"
@interface HotCarPictureViewController ()

@end
float pagWidth = 200,pageHieght=150;
NSInteger pageNumber = 3;
@implementation HotCarPictureViewController

- (void)dealloc
{
    [_scrollView release];
    [super dealloc];
}

- (void)backToHotZongShu:(UIBarButtonItem *)btn
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)loadView
{
    HotPictureDetailView *hotCarPicView = [[HotPictureDetailView alloc] init];
    self.view = hotCarPicView;
    self.scrollView = hotCarPicView.scrollView;
    [hotCarPicView release];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    NSLog(@"%@",NSStringFromCGPoint(scrollView.contentOffset));
    if (scrollView.contentOffset.x<0) {
        [scrollView setContentOffset:CGPointMake(scrollView.frame.size.width*2, 0) animated:NO];
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSLog(@"end%@",NSStringFromCGPoint(scrollView.contentOffset));
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:41/255.0 green:129/255.0 blue:255/255.0 alpha:1];
    
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backToHotZongShu:)];
    [backBtn setTintColor:[UIColor whiteColor]];
    self.navigationItem.leftBarButtonItem = backBtn;
    [backBtn release];
    
    _scrollView.backgroundColor = [UIColor grayColor];
    _scrollView.contentSize = CGSizeMake(pagWidth*pageNumber, 0);
    _scrollView.contentOffset = CGPointMake(0, 0);
    _scrollView.pagingEnabled = YES;//整页滑动
    //s.bounces = NO;//边界是否回弹,默认Yes
    // s.maximumZoomScale = 10;//最大放大倍数
    //s.minimumZoomScale = 0.5;//最小缩小倍数
    //s.zoomScale = 2;//当前放大的倍数
    _scrollView.delegate = self;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    
    for (int i=0; i<pageNumber ; i++) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(i*pagWidth,0, pagWidth, 150)];
        NSLog(@"%@",NSStringFromCGRect(label.frame));
        if (i%2) {
            label.backgroundColor = [UIColor greenColor];
        }
        else
        {
            label.backgroundColor = [UIColor yellowColor];
        }
        label.textAlignment = NSTextAlignmentCenter;
        label.text = [NSString stringWithFormat:@"第%d页",i+1];
        [_scrollView addSubview:label];
        [label release];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
